/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-17
*/
package com.rzico.basics.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.model.ShopVo;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.basics.service.ProductService;
import com.rzico.core.entity.SysUser;
import com.rzico.core.service.SysUserService;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.basics.entity.Shop;
import com.rzico.basics.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

/**
 * 店铺/仓库控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-02-17
 */
@Api(description = "店铺/仓库接口")
@RestController
@RequestMapping("/shop")
public class
ShopController extends BaseController {

    @Autowired
    private ShopService shopService;

    @Autowired
    private EnterpriseService enterpriseService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private ProductService productService;

    /**
     * 获取商户的店铺
     *
     * @return
    */
    @ApiOperation("获取商户的店铺")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mchId", value = "商户id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lat", value = "lat", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "lng", value = "lng", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "productId", value = "商品Id", dataType = "Long", paramType = "query")
    })
    public CommResult<Shop> list(Double lat,Double lng,String mchId,Integer type, Pageable pageable, Long productId) {
        Map<String, Object> params = new HashMap<String, Object>();

        Enterprise enterprise = enterpriseService.findByMch(mchId);
        if (enterprise!=null) {
            params.put("enterpriseId", enterprise.getId());
        } else {
            return CommResult.error("没有开通企业");
        }

        params.put("type",0);

        if (productId!=null) {
            params.put("supplierId",productService.selectByPrimaryKey(productId).getSupplierId());
        }
        
        List<ShopVo> list = shopService.selectLbsList(params,lat,lng);
        return CommResult.success(list);
    }

    /**
     * 获取服务商下的店铺
     *
     * @return
     */
    @ApiOperation("获取服务商下的店铺")
    @GetMapping("/isvList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isvId", value = "ISVid", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lat", value = "lat", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "lng", value = "lng", dataType = "Double", paramType = "query"),
    })
    public CommResult<Shop> isvList(Double lat,Double lng,String isvId, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();

        params.put("type",0);
        params.put("isvId",isvId);

        List<ShopVo> list = shopService.selectLbsList(params,lat,lng);
        return CommResult.success(list);
    }

}
